<template>
  <div
    class="publishTop"
    :style="{ background: '#f4f5f5', height: publishTopHeight }"
  >
    <div class="publish" :style="{ height: publishHeight }">
      <div class="pcontent">
        <el-form ref="form" :model="form" label-width="110px">
          <el-form-item label="模块名称：">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="流程标识：">
            <el-input
              v-model="form.modulesKey"
              placeholder="请输入字母开头"
            ></el-input>
          </el-form-item>
          <el-form-item label="模块备注：">
            <el-input type="textarea" v-model="form.modulesDesc"></el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" :loading="loading" @click="add()"
              >立即提交</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { add } from "@/api/modules/index";
export default {
  data() {
    return {
      publishTopHeight: window.innerHeight - 100 + "px",
      publishHeight: window.innerHeight - 130 + "px",
      loading: false,
      form: {
        id: "",
        name: "",
        fuMenuCode: "",
        fieldJson: "",
        modulesXml: "",
        modulesSvg: "",
        status: "",
        modulesDesc: "",
        buttons: {},
        modulesKey: "", //这个是流程标识
        isMenu: "", //这个是否需要菜单
        menuName: "", //菜单名称
        tableName: "", //数据库名
      },

      originForm: "",

      menus: [],
    };
  },
  mounted() {
  },
  methods: {
    add() {
      this.loading = true;
      if (this.form.name == "") {
        this.$notify({
          title: "请填写模块名称",
          type: "error",
          duration: 2500,
        });
        this.loading = false;
        return false;
      }
      if (this.form.modulesKey == "") {
        this.$notify({
          title: "请填写模块标识",
          type: "error",
          duration: 2500,
        });
        this.loading = false;
        return false;
      }

      //将所有的按钮信息传到后台去
      this.form.buttons = this.$store.state.activiti.btns;
      add(this.form).then((res) => {
        if (res.code == 200) {
          this.$parent.editorVisible = false;
          this.$parent.closePage();
        }
      });
    },
    normalizer(node) {
      if (!node.data) {
        node.data = {
          code: "0",
          name: "请选择菜单",
        };
      }
      if (node.children == null || !node.children.length) {
        delete node.children;
      }
      return {
        id: node.data.code,
        label: node.data.name,
        children: node.children,
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.publishTop {
  padding-top: 15px;
  .publish {
    width: 1000px;
    margin: 0 auto;
    border-radius: 5px;

    min-height: 500px;
    box-shadow: 1px 1px 5px #e0e0e0;
    background: #ffffff;
    .pcontent {
      padding: 20px;
      line-height: 50px;
    }
  }
}
</style>
